package com.holy.sh.couviewholy.myview;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.Region;
import android.graphics.RegionIterator;
import android.util.AttributeSet;
import android.view.View;

/**
 * Holy Email :victorhhl@163.com
 * Create by Holy on ${data}
 * Description :
 */
public class RagoinView extends View {

    public RagoinView(Context context) {
        super(context);
    }

    public RagoinView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
            Paint paint=new Paint();
            paint.setColor(Color.RED);
            paint.setStyle(Paint.Style.STROKE);
            paint.setStrokeWidth(5);


        Path ovalPath=new Path();
        RectF rectF=new RectF(50,50,200,500);
        ovalPath.addOval(rectF,Path.Direction.CCW);

        Region rgn=new Region(10,10,100,100);
        rgn.setPath(ovalPath,new Region(50,50,200,200));
        drawRegion(canvas,rgn,paint);

    }

    private void drawRegion(Canvas canvas, Region rgn, Paint paint) {
        RegionIterator iterator=new RegionIterator(rgn);
        Rect r=new Rect();
        while (iterator.next(r)){
            canvas.drawRect(r,paint);
        }
    }

}
